﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StickBehaviour : UnitBehaviour
{
    public Stick Stick
    {
        get { return Unit as Stick; }
        set { Unit = value; }
    }

    public override void Init()
    {
        base.Init();

        var g = Unit as Stick;
        var stickObj = NewChildObj("stick");
        var lr = stickObj.AddComponent<LineRenderer>();
        var pts = new Vector3[2];
        pts[0] = new Vector3(0, -g.Length / 2);
        pts[1] = new Vector3(0, g.Length / 2);

        lr.loop = true;
        lr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        lr.startWidth = lr.endWidth = 0.1f;
        lr.startColor = lr.endColor = Color.green;
        lr.material = DefaultMaterial;
        lr.useWorldSpace = false;
        lr.positionCount = pts.Length;
        lr.SetPositions(pts);
    }
}
